<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // var arr = [6,7,21,5,8,7,11,22,223]
        // var a = new Set(arr)
        // console.log(a)
        // var sorted = Array.from(a).sort((a,b)=>{return a-b})
        // var son = []
        // for(let a of sorted){
        //     var isgood = false
        //     for(var i=2;i<a;i++){
        //         if(a%i==0){
        //             isgood = true
        //             console.log(i)
        //             break
        //         }
        //     }
        //     if(!isgood){son.push(a)}
        // }
        // console.log(son)
        boxes = [3, 5, 1, 7, 10, 8]
        target = 21
        function findBoxesCombinations(boxes, target) {
            // write code here
            var answer = 0
            boxes = boxes.sort((a, b) => { return a - b })
            for (let index in boxes) {
                if (boxes[index] > target) {
                    break
                }
                if (boxes[index] == target) {
                    answer++
                    break
                }
                else {
                    var newins = Array.from(boxes)
                    sub = newins.shift()
                    target -= sub
                    answer += findBoxesCombinations(newins, target)
                }

            }
            return answer
        }
        a = findBoxesCombinations(boxes,target)
        console.log(a)
    </script>
</body>

</html>